﻿using Abp.Extensions;
using AutoMapper;
using ImageProcessor.Imaging.Formats;
using System;
using System.Reflection;

namespace FutureApp.Media.Mapper
{
    internal class ImageProcessorProfile : Profile
    {
        private static readonly Assembly ImageProccesorAssembly = typeof(ISupportedImageFormat).Assembly;

        public ImageProcessorProfile()
        {
            this.CreateMap<string, ISupportedImageFormat>()
                .ConvertUsing(format =>
                {
                    var type = ImageProccesorAssembly.GetType($"ImageProcessor.Imaging.Formats.{format.ToPascalCase()}Format");                    
                    return type == null ? null : Activator.CreateInstance(type) as ISupportedImageFormat;
                });
        }
    }
}
